Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix delayvar not correct in concat mode #632

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

CloudyDory
Copy link
Contributor

Description

The delay variable with "concat" update method seems not being updated correctly. See the following code for example:

import brainpy.math as bm

spike = bm.zeros(5, dtype=bm.bool)
delay_len = 2

print('Rotation mode:')
spike_buffer = bm.LengthDelay(spike, delay_len, update_method='rotation')
for i in range(5):
    spike[i] = True
    spike_buffer.update(spike)
    spike_delay = spike_buffer.retrieve(delay_len)
    
    print(spike.value)
    print(spike_delay)
    print('')
    
print('Concat mode:')
spike = bm.zeros(5, dtype=bm.bool)
spike_buffer = bm.LengthDelay(spike, delay_len=delay_len, update_method='concat')
for i in range(5):
    spike[i] = True
    spike_buffer.update(spike)
    spike_delay = spike_buffer.retrieve(delay_len)
    
    print(spike.value)
    print(spike_delay)
    print('')

Output:

Rotation mode:
[ True False False False False]
[False False False False False]

[ True  True False False False]
[False False False False False]

[ True  True  True False False]
[ True False False False False]

[ True  True  True  True False]
[ True  True False False False]

[ True  True  True  True  True]
[ True  True  True False False]

Concat mode:
[ True  True  True  True  True]
[False False False False False]

[ True  True  True  True  True]
[False False False False False]

[ True  True  True  True  True]
[False False False False False]

[ True  True  True  True  True]
[False False False False False]

[ True  True  True  True  True]
[False False False False False]

The cause is in line 476 of delayvars.py, the code only update the first row of the data buffer matrix.

After fixing the issue, the above test code can run correctly:

Rotation mode:
[ True False False False False]
[False False False False False]

[ True  True False False False]
[False False False False False]

[ True  True  True False False]
[ True False False False False]

[ True  True  True  True False]
[ True  True False False False]

[ True  True  True  True  True]
[ True  True  True False False]

Concat mode:
[ True False False False False]
[False False False False False]

[ True  True False False False]
[False False False False False]

[ True  True  True False False]
[ True False False False False]

[ True  True  True  True False]
[ True  True False False False]

[ True  True  True  True  True]
[ True  True  True False False]

Copy link
Collaborator

@chaoming0625 chaoming0625 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR.

@chaoming0625 chaoming0625 merged commit 64d8f54 into brainpy:master Feb 22, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants